<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\BaseController;
use Illuminate\Http\Request;

class LikeController extends BaseController
{
    public $validate = [
        "add" => ["rules" => [
            "target_id" => "required|string|max:24",
            "target_type" => "required",
        ]],
        "cancel" => ["rules" => [
            "target_id" => "required|string|max:24",
            "target_type" => "required",
        ]],
    ];

    /**
     * @path /like/add
     * @category 点赞
     * @title 点赞
     * @method POST
     * @params [{"name":"target_id","type":"text","required":1,"example":"","desc":"主体ID"},{"name":"target_type","type":"text","required":1,"example":"","desc":"主体类型"}]
     * @resBody {"success":true,"statusCode":200,"result":true,"message":"OK"}
     */
    public function add(Request $request)
    {
        $params = $request->all();
        $loadData = [
            'target_id' => $params['target_id'],
            'target_type' => $params['target_type'],
            'sender_id' => $this->getCurrentUserId(),
        ];

        $createLikeResult = service()->LikeService->createLike($loadData);

        return $this->apiReturn($createLikeResult);
    }

    /**
     * @path /like/cancel
     * @category 点赞
     * @title 取消点赞
     * @method POST
     * @params [{"name":"target_id","type":"text","required":1,"example":"","desc":"主体ID"},{"name":"target_type","type":"text","required":1,"example":"","desc":"主体类型"}]
     * @resBody {"success":true,"statusCode":200,"result":true,"message":"OK"}
     */
    public function cancel(Request $request)
    {
        $params = $request->all();
        $loadData = [
            'target_id' => $params['target_id'],
            'target_type' => $params['target_type'],
            'sender_id' => $this->getCurrentUserId(),
        ];

        $cancelLikeResult = service()->LikeService->cancelLike($loadData);

        return $this->apiReturn($cancelLikeResult);
    }
}
